clc, clear
x = [0 0 1; 0 1 1; 1 0 1; 1 1 1]; % batch_size = 4
y = [0 1 1 0]';
% nn size: 3-->4-->1
syn0 = 2 * rand(3,4) - 1;
syn1 = 2 * rand(4,2) - 1;
for j = 1:60000
    l0 = x;
    l1 = sigmoid(l0 * syn0);
    l2 = sigmoid(l1 * syn1);

    l2_error = y - l2;
    if mod(j, 10000) == 0
        fprintf('%.2f\n', mean(abs(l2_error)));
    end

    l2_delta = l2_error .* sigmoid(l2, true);
    l1_error = l2_delta * syn1';
    l1_delta = l1_error .* sigmoid(l1, true);
    syn1 = syn1 + l1' * l2_delta;
    syn0 = syn0 + l0' * l1_delta;
end

% forward perdicion
%sigmoid(sigmoid(x*syn0)*syn1)

